﻿<!-- CartoonModel.php-->
<?php 
	//require 'ConnDB.php';
	//require 'config.php';
	require 'Model.php';
	class CartoonModel extends Model{
		function __Construct(){
			parent::__Construct();
		}
		function getCartoonList(){
			$sql = "select * from cartoons";
			$data = $this->conn->query($sql);
			/*var_dump($data);
			var_dump($sql);*/
			return $data;


			//var_dump($data);
		}
		function getCartoonByID($id){
			$sql = "select * from cartoons where id=".$id;
			$data = $this->conn->query($sql);
			return $data;
		}

		function UpdateCartoon($data){
			if(!empty($_FILES["pic"]["name"])){
  				$pic = $this->uploadfile('pic','./upload/',array('jpg','gif','png'));
  			}
		    else{
		  		$pic='';
		  	}
		  	$video = array(
				'id' =>$_POST['id'],		
				'name' => trim($_POST['name']),  
				
				'intro' => $_POST['intro'],
                 'size' => $_POST['size'],
                'tid' => $_POST['tid'],
				'uploadtime' => $_POST['uploadtime'],
               'address' => $_POST['address'],
				//'hint' => $_POST['hint'],
				
				'pic'=>$pic
				);
			/*$sql = "insert into cartoons values ('$video[id]','$video[name]','$video[intro]','$video[size]','$video[uid]','$video[uploadtime]','$video[hint]','$video[address]','$video[pic]')";*/
			$sql="update cartoons set id='$video[id]',name='$video[name]',intro='$video[intro]',size='$video[size]',tid='$video[tid]',uploadtime='$video[uploadtime]',address='$video[address]',pic='$video[pic]' where id=".$video['id'];
			//echo "$sql";
			$result = $this->conn->query($sql);
			return $result;
		}

		function addCartoon($data){
			//var_dump($data);
			//如果选择了头像，则上传头像文件
			if(!empty($_FILES["pic"]["name"])){
  				//$pic = parent::uploadfile('pic','Upload/',array('png','jpg','gif'));
  				$pic = $this->uploadfile('pic','./upload/',array('jpg','gif','png'));
  			}
		    else{
		  		$pic='';
		  	}
			$video = array(		
				'name' => trim($data['name']),  
				
				'intro' => $data['intro'],
				'size' => $data['size'],
                'tid' => $data['tid'],
				'uploadtime' => $data['uploadtime'],
				//'hint' => $data['hint'],
				'address' => $data['address'],
				'pic'=>$pic
				);
			$keys = implode(',',array_keys($video));
			$values = implode("','",array_values($video));
			/*$sql = "insert into cartoons values ('$video[id]','$video[name]','$video[intro]','$video[size]','$video[uid]','$video[uploadtime]','$video[hint]','$video[address]','$video[pic]')";*/
			$sql="insert into cartoons ({$keys}) VALUES ('{$values}')";
			//echo "$sql";
			$result = $this->conn->query($sql);
			return $result;
		}

		function DelCartoon($id){
			$sql = "Delete from cartoons where id=".$id;
			$data = $this->conn->query($sql);
			return $data;
		}
		 /*function getCartoonByID($id){
			$sql = "select * from cartoons where id=".$id;
			$data = $this->conn->query($sql);
			return $data;
		}*/
		function search(){
$sql = 'select uid, uname, gender, birthdate, hobby, degree, intro, pic from users';
  if(@$_POST['key'])  {
    $key = trim($_POST['key']);
    $sql = $sql." where uname like '%{$key}%' ";
  }
		}
		function search1($key){
	$sql = "select * from cartoons where name like '%{$key}%'";
	$data = $this->conn->query($sql);
	
		return $data;
}
		
	}
 ?>